package com.letao.server.dto;

import com.letao.server.entity.SpuInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * ES数据库存储的SPU信息类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EsSpuInfoDTO {
    private Long id;
    private String spuName;
    private Integer oneCategoryId;
    private Integer twoCategoryId;
    private String descript;
    private List<String> keyWords;
    private Double priceLow;
    private Double priceHigh;
    private String spuImage;
    private List<String> suggection;

    public EsSpuInfoDTO(SpuInfo spuInfo) {
        this.id = spuInfo.getId();
        this.spuName = spuInfo.getSpuName();
        this.spuImage = spuInfo.getSpuImage();
        this.oneCategoryId = spuInfo.getOneCategoryId();
        this.twoCategoryId = spuInfo.getTwoCategoryId();
        this.descript = spuInfo.getDescript();
        this.priceHigh = spuInfo.getPriceHigh();
        this.priceLow = spuInfo.getPriceLow();
        this.keyWords = Arrays.stream(spuInfo.getKeyWords().split(",")).toList();
        this.suggection = new ArrayList<>();
        this.suggection.addAll(this.keyWords);
        this.suggection.add(this.spuName);
    }
}
